﻿using System.Linq;
using Rhizome.Contract;
using System.Diagnostics;

namespace Rhizome.Model
{
    public class AndCriterion<TPlant> : AggregateCriterionBase<TPlant>
    {
        public AndCriterion(params ICriterion[] criterions) : base(criterions)
        {
        }

        public AndCriterion()
        {
        }

		/// <summary>
		/// XAML "macro".
		/// Adds specific value to Criterions
		/// </summary>
		public ICriterion If
		{
			[DebuggerStepThrough]
			get { return Criterions.FirstOrDefault(); }
			[DebuggerStepThrough]
			set { Criterions.Add(value); }
		}

		/// <summary>
		/// XAML "macro".
		/// Adds specific value to Criterions
		/// </summary>
		public ICriterion And
		{
			[DebuggerStepThrough]
			get { return Criterions.Skip(1).FirstOrDefault(); }
			[DebuggerStepThrough]
			set { Criterions.Add(value); }
		}

        public override bool Test()
        {
            return Criterions.All(criterion => criterion.Test());
        }
    }

    public sealed class AndCriterion : AndCriterion<object>
    {
    	public AndCriterion(params ICriterion[] criterions) : base(criterions)
    	{
    	}

    	public AndCriterion()
    	{
    	}
    }
}